package com.goktech.mapper;

import com.goktech.entity.Book;
import com.goktech.entity.User;
import com.goktech.entity.collect;
import com.goktech.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.Date;

/**
 * @ClassName testCollectMapper
 * @Description TODO
 * @Author 邱华英
 * @Date 2022/10/3 20:21
 * @Version 1.0
 */

public class testCollectMapper {
    SqlSession session = null;
    CollectMapper collectMapper = null;

    @Before
    public void before() throws IOException {
        session = SqlSessionUtil.getSqlSession();
        collectMapper = session.getMapper(CollectMapper.class);
    }

    @After
    public void after(){
        session.close();
    }

    @Test
    public void testselectAll(){
        User u = new User();
        u.setId(6);

        System.out.println(collectMapper.selectAll(u,0,6));
    }

    @Test
    public void testinsertCollect(){
        collect c =new collect();
        c.setBookId(6);
        c.setUserId(1);
        c.setCollectTime(new Date());
        System.out.println(collectMapper.insertCollect(c));
    }

    @Test
    public void testdeleteCollect(){
        collect c =new collect();
        c.setBookId(6);
        c.setUserId(1);
        c.setCollectTime(new Date());
        System.out.println(collectMapper.deleteCollect(c));
    }

    @Test
    public void testfindByCollectOne(){
        collect c =new collect();
        c.setBookId(6);
        c.setUserId(1);
        c.setCollectTime(new Date());
        System.out.println(collectMapper.findByCollectOne(c));
    }

    @Test
    public void testfindByLikeBookName(){
        User u = new User();
        Book b = new Book();

        u.setId(6);
        b.setId(5);
        b.setBName("%绝%");

        System.out.println(collectMapper.findByLikeBookName(u, b));
    }

    @Test
    public void testfindByLikeAuthor(){
        User u = new User();
        u.setId(6);
        Book b = new Book();
        b.setBAuthor("%张%");
        System.out.println(collectMapper.findByLikeAuthor(u, b));
    }
}
